<html>
<head>
    <title>Demo - Covnert JSON to CSV</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript" src="https://github.com/douglascrockford/JSON-js/raw/master/json2.js"></script>

    <script type="text/javascript">
        // JSON to CSV Converter
        function ConvertToCSV(objArray) {
            var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
            var str = '';

            for (var i = 0; i < array.length; i++) {
                var line = '';
                for (var index in array[i]) {
                    if (line != '') line += ','

                    line += array[i][index];
                }

                str += line + '\r\n';
            }

            return str;
        }

        // Example
        $(document).ready(function () {

            // Create Object
            var items =[{"nick":"","comment":"","activity":"Walk","color":"FFFF00","abbr":"","lat":null,"lon":null,"online":null,"latency":"60000","deviceId":"172.30.49.27","mode":"","refresh":"10000","gpsPrecision":null,"positions":[],"id":251,"version":1},{"nick":"d","comment":"","activity":"Walk","color":"FFFF00","abbr":"d","lat":"37.88767863","lon":"-4.79399759","online":"Sat Jan 26 18:24:50 UTC 2013","latency":"300000","deviceId":"ea0dcf87d1a39abc","mode":"","refresh":"30000","gpsPrecision":"18","positions":[{"lat":"37.8878536","lon":"-4.79395551","hora":"Sat Jan 26 18:18:55 UTC 2013","gpsPrecision":"16","id":285,"version":1},{"lat":"37.88756967","lon":"-4.79408331","hora":"Sat Jan 26 18:10:40 UTC 2013","gpsPrecision":"19","id":279,"version":1},{"lat":"37.88770024","lon":"-4.79398047","hora":"Sat Jan 26 18:20:52 UTC 2013","gpsPrecision":"18","id":287,"version":1},{"lat":"37.88760641","lon":"-4.79402059","hora":"Sat Jan 26 18:15:39 UTC 2013","gpsPrecision":"18","id":283,"version":1},{"lat":"37.88741137","lon":"-4.79387395","hora":"Sat Jan 26 17:58:39 UTC 2013","gpsPrecision":"19","id":270,"version":1},{"lat":"37.88740656","lon":"-4.79384339","hora":"Sat Jan 26 17:56:53 UTC 2013","gpsPrecision":"19","id":268,"version":1},{"lat":"37.88746938","lon":"-4.79393375","hora":"Sat Jan 26 18:07:32 UTC 2013","gpsPrecision":"18","id":276,"version":1},{"lat":"37.88771355","lon":"-4.79405426","hora":"Sat Jan 26 18:19:50 UTC 2013","gpsPrecision":"19","id":286,"version":1},{"lat":"37.88723687","lon":"-4.7937873","hora":"Sat Jan 26 17:52:41 UTC 2013","gpsPrecision":"18","id":265,"version":1},{"lat":"37.88767792","lon":"-4.79400412","hora":"Sat Jan 26 18:23:50 UTC 2013","gpsPrecision":"16","id":289,"version":1},{"lat":"37.88763877","lon":"-4.79397192","hora":"Sat Jan 26 18:13:35 UTC 2013","gpsPrecision":"18","id":282,"version":1},{"lat":"37.88699835","lon":"-4.79404295","hora":"Sat Jan 26 17:49:47 UTC 2013","gpsPrecision":"17","id":253,"version":1},{"lat":"37.88741559","lon":"-4.7938647","hora":"Sat Jan 26 17:57:34 UTC 2013","gpsPrecision":"16","id":269,"version":1},{"lat":"37.88758098","lon":"-4.79401095","hora":"Sat Jan 26 18:16:35 UTC 2013","gpsPrecision":"18","id":284,"version":1},{"lat":"37.88765388","lon":"-4.79394203","hora":"Sat Jan 26 18:12:43 UTC 2013","gpsPrecision":"18","id":281,"version":1},{"lat":"37.88735353","lon":"-4.79383076","hora":"Sat Jan 26 17:55:42 UTC 2013","gpsPrecision":"19","id":267,"version":1},{"lat":"37.88768492","lon":"-4.79397179","hora":"Sat Jan 26 18:22:48 UTC 2013","gpsPrecision":"19","id":288,"version":1},{"lat":"37.8874326","lon":"-4.79389199","hora":"Sat Jan 26 18:03:28 UTC 2013","gpsPrecision":"19","id":272,"version":1},{"lat":"37.88722595","lon":"-4.79391239","hora":"Sat Jan 26 17:50:38 UTC 2013","gpsPrecision":"19","id":264,"version":1},{"lat":"37.8874298","lon":"-4.79389172","hora":"Sat Jan 26 18:02:32 UTC 2013","gpsPrecision":"19","id":271,"version":1},{"lat":"37.88767863","lon":"-4.79399759","hora":"Sat Jan 26 18:24:50 UTC 2013","gpsPrecision":"18","id":290,"version":1},{"lat":"37.88740593","lon":"-4.79395588","hora":"Sat Jan 26 18:06:43 UTC 2013","gpsPrecision":"18","id":275,"version":1},{"lat":"37.88751283","lon":"-4.7939684","hora":"Sat Jan 26 18:09:41 UTC 2013","gpsPrecision":"19","id":278,"version":1},{"lat":"37.88758687","lon":"-4.79406911","hora":"Sat Jan 26 18:11:42 UTC 2013","gpsPrecision":"19","id":280,"version":1},{"lat":"37.88744839","lon":"-4.79389102","hora":"Sat Jan 26 18:04:29 UTC 2013","gpsPrecision":"19","id":273,"version":1},{"lat":"37.88729357","lon":"-4.79381701","hora":"Sat Jan 26 17:53:46 UTC 2013","gpsPrecision":"18","id":266,"version":1},{"lat":"37.88745246","lon":"-4.79389176","hora":"Sat Jan 26 18:05:29 UTC 2013","gpsPrecision":"19","id":274,"version":1},{"lat":"37.88749375","lon":"-4.79402029","hora":"Sat Jan 26 18:08:35 UTC 2013","gpsPrecision":"19","id":277,"version":1}],"id":252,"version":29},{"nick":"Eva24","comment":"","activity":"Walk","color":"FFFF00","abbr":"E","lat":"37.894396651536226","lon":"-4.7746929712593555","online":"Tue Jan 29 14:21:28 UTC 2013","latency":"60000","deviceId":"ad04180982c8106c","mode":"","refresh":"30000","gpsPrecision":"15","positions":[{"lat":"37.8909727698192","lon":"-4.781736200675368","hora":"Tue Jan 29 14:10:53 UTC 2013","gpsPrecision":"5","id":381,"version":1},{"lat":"37.89404553361237","lon":"-4.779280303046107","hora":"Mon Jan 28 07:00:30 UTC 2013","gpsPrecision":"15","id":354,"version":1},{"lat":"37.88917543832213","lon":"-4.78922693990171","hora":"Sun Jan 27 13:25:45 UTC 2013","gpsPrecision":"30","id":348,"version":1},{"lat":"37.889089859090745","lon":"-4.792399238795042","hora":"Sun Jan 27 12:14:58 UTC 2013","gpsPrecision":"15","id":335,"version":1},{"lat":"37.88811340928078","lon":"-4.79597152210772","hora":"Sun Jan 27 13:20:51 UTC 2013","gpsPrecision":"15","id":343,"version":1},{"lat":"37.891223933547735","lon":"-4.796073865145445","hora":"Sun Jan 27 11:45:27 UTC 2013","gpsPrecision":"15","id":318,"version":1},{"lat":"37.89264617487788","lon":"-4.781151143833995","hora":"Tue Jan 29 14:13:46 UTC 2013","gpsPrecision":"15","id":384,"version":1},{"lat":"37.893822197802365","lon":"-4.778530290350318","hora":"Sun Jan 27 13:30:00 UTC 2013","gpsPrecision":"40","id":351,"version":1},{"lat":"37.89142480585724","lon":"-4.780798265710473","hora":"Tue Jan 29 14:11:53 UTC 2013","gpsPrecision":"15","id":382,"version":1},{"lat":"37.89075467269868","lon":"-4.795929444953799","hora":"Sun Jan 27 11:44:08 UTC 2013","gpsPrecision":"15","id":316,"version":1},{"lat":"37.888948917388916","lon":"-4.79449194855988","hora":"Sun Jan 27 12:08:01 UTC 2013","gpsPrecision":"15","id":333,"version":1},{"lat":"37.891223933547735","lon":"-4.796073865145445","hora":"Sun Jan 27 11:45:27 UTC 2013","gpsPrecision":"15","id":317,"version":1},{"lat":"37.88695611990988","lon":"-4.795921398326755","hora":"Sun Jan 27 13:19:46 UTC 2013","gpsPrecision":"15","id":342,"version":1},{"lat":"37.89547573775053","lon":"-4.780463241040707","hora":"Mon Jan 28 14:17:58 UTC 2013","gpsPrecision":"15","id":368,"version":1},{"lat":"37.887394283898175","lon":"-4.796659927815199","hora":"Sun Jan 27 13:18:04 UTC 2013","gpsPrecision":"15","id":341,"version":1},{"lat":"37.891782713122666","lon":"-4.7960577718913555","hora":"Sun Jan 27 11:48:02 UTC 2013","gpsPrecision":"15","id":322,"version":1},{"lat":"37.89017967414111","lon":"-4.797090254724026","hora":"Sun Jan 27 12:00:28 UTC 2013","gpsPrecision":"15","id":331,"version":1},{"lat":"37.889814767986536","lon":"-4.798061046749353","hora":"Sun Jan 27 11:31:12 UTC 2013","gpsPrecision":"15","id":308,"version":1},{"lat":"37.89363549090922","lon":"-4.780419487506151","hora":"Tue Jan 29 14:16:04 UTC 2013","gpsPrecision":"15","id":386,"version":1},{"lat":"37.89277081377804","lon":"-4.780868422240019","hora":"Tue Jan 29 14:14:40 UTC 2013","gpsPrecision":"10","id":385,"version":1},{"lat":"37.893086769618094","lon":"-4.7992590721696615","hora":"Sun Jan 27 12:46:18 UTC 2013","gpsPrecision":"10","id":339,"version":1},{"lat":"37.89312901441008","lon":"-4.780075661838055","hora":"Mon Jan 28 07:01:12 UTC 2013","gpsPrecision":"5","id":355,"version":1},{"lat":"37.893662354908884","lon":"-4.799740696325898","hora":"Sun Jan 27 13:14:03 UTC 2013","gpsPrecision":"15","id":340,"version":1},{"lat":"37.895517689175904","lon":"-4.780538007616997","hora":"Tue Jan 29 14:18:39 UTC 2013","gpsPrecision":"15","id":388,"version":1},{"lat":"37.89296213071793","lon":"-4.7802709601819515","hora":"Tue Jan 29 07:01:16 UTC 2013","gpsPrecision":"15","id":375,"version":1},{"lat":"37.89408438373357","lon":"-4.780435413122177","hora":"Mon Jan 28 14:17:03 UTC 2013","gpsPrecision":"15","id":367,"version":1},{"lat":"37.89155506063253","lon":"-4.78091686964035","hora":"Mon Jan 28 14:11:38 UTC 2013","gpsPrecision":"15","id":361,"version":1},{"lat":"37.89180320687592","lon":"-4.796248376369476","hora":"Sun Jan 27 11:48:41 UTC 2013","gpsPrecision":"15","id":324,"version":1},{"lat":"37.89155786857009","lon":"-4.796294728294015","hora":"Sun Jan 27 11:46:40 UTC 2013","gpsPrecision":"15","id":319,"version":1},{"lat":"37.89173342753202","lon":"-4.7962550818920135","hora":"Sun Jan 27 11:52:48 UTC 2013","gpsPrecision":"10","id":325,"version":1},{"lat":"37.891782713122666","lon":"-4.7960577718913555","hora":"Sun Jan 27 11:48:02 UTC 2013","gpsPrecision":"15","id":321,"version":1},{"lat":"37.896473980508745","lon":"-4.779459089040756","hora":"Mon Jan 28 14:20:49 UTC 2013","gpsPrecision":"15","id":370,"version":1},{"lat":"37.88855438120663","lon":"-4.791907137259841","hora":"Sun Jan 27 13:22:59 UTC 2013","gpsPrecision":"15","id":346,"version":1},{"lat":"37.89283376187086","lon":"-4.780658790841699","hora":"Mon Jan 28 07:07:31 UTC 2013","gpsPrecision":"15","id":356,"version":1},{"lat":"37.890468263067305","lon":"-4.79585031978786","hora":"Sun Jan 27 11:42:59 UTC 2013","gpsPrecision":"10","id":313,"version":1},{"lat":"37.890307288616896","lon":"-4.7969872411340475","hora":"Sun Jan 27 11:59:22 UTC 2013","gpsPrecision":"15","id":330,"version":1},{"lat":"37.8952158568427","lon":"-4.780484531074762","hora":"Tue Jan 29 14:18:07 UTC 2013","gpsPrecision":"15","id":387,"version":1},{"lat":"37.894243597984314","lon":"-4.777792599052191","hora":"Sun Jan 27 13:30:14 UTC 2013","gpsPrecision":"40","id":352,"version":1},{"lat":"37.88811340928078","lon":"-4.79597152210772","hora":"Sun Jan 27 13:20:51 UTC 2013","gpsPrecision":"15","id":344,"version":1},{"lat":"37.90252793580294","lon":"-4.789799842983484","hora":"Sun Jan 27 11:12:49 UTC 2013","gpsPrecision":"45","id":305,"version":1},{"lat":"37.894703513011336","lon":"-4.778119241818786","hora":"Sun Jan 27 09:20:06 UTC 2013","gpsPrecision":"45","id":302,"version":1},{"lat":"37.89253674913198","lon":"-4.781184755265713","hora":"Tue Jan 29 07:02:46 UTC 2013","gpsPrecision":"15","id":376,"version":1},{"lat":"37.888739705085754","lon":"-4.7907342575490475","hora":"Sun Jan 27 13:23:36 UTC 2013","gpsPrecision":"5","id":347,"version":1},{"lat":"37.8905055206269","lon":"-4.7961110807955265","hora":"Sun Jan 27 11:56:43 UTC 2013","gpsPrecision":"15","id":328,"version":1},{"lat":"37.89126047864556","lon":"-4.781050058081746","hora":"Mon Jan 28 14:10:35 UTC 2013","gpsPrecision":"10","id":359,"version":1},{"lat":"37.894396651536226","lon":"-4.7746929712593555","hora":"Tue Jan 29 14:21:28 UTC 2013","gpsPrecision":"15","id":389,"version":1},{"lat":"37.890374385751784","lon":"-4.786392347887158","hora":"Sun Jan 27 13:26:23 UTC 2013","gpsPrecision":"15","id":350,"version":1},{"lat":"37.88912087213248","lon":"-4.792552292346954","hora":"Sun Jan 27 12:15:43 UTC 2013","gpsPrecision":"15","id":336,"version":1},{"lat":"37.89576826617122","lon":"-4.778793901205063","hora":"Tue Jan 29 06:57:02 UTC 2013","gpsPrecision":"15","id":372,"version":1},{"lat":"37.892901697196066","lon":"-4.780792482197285","hora":"Mon Jan 28 14:13:55 UTC 2013","gpsPrecision":"15","id":365,"version":1},{"lat":"37.89180320687592","lon":"-4.796248376369476","hora":"Sun Jan 27 11:48:41 UTC 2013","gpsPrecision":"15","id":323,"version":1},{"lat":"37.89126047864556","lon":"-4.781050058081746","hora":"Mon Jan 28 14:10:35 UTC 2013","gpsPrecision":"10","id":360,"version":1},{"lat":"37.890374385751784","lon":"-4.786392347887158","hora":"Sun Jan 27 13:26:23 UTC 2013","gpsPrecision":"15","id":349,"version":1},{"lat":"37.890813974663615","lon":"-4.79595341719687","hora":"Sun Jan 27 11:55:48 UTC 2013","gpsPrecision":"10","id":327,"version":1},{"lat":"37.89035812485963","lon":"-4.796353988349438","hora":"Sun Jan 27 11:41:46 UTC 2013","gpsPrecision":"10","id":312,"version":1},{"lat":"37.89347585756332","lon":"-4.779386166483164","hora":"Tue Jan 29 07:00:15 UTC 2013","gpsPrecision":"15","id":374,"version":1},{"lat":"37.89311405271292","lon":"-4.798878952860832","hora":"Sun Jan 27 12:45:56 UTC 2013","gpsPrecision":"15","id":338,"version":1},{"lat":"37.88899816107005","lon":"-4.794361442327499","hora":"Sun Jan 27 12:06:58 UTC 2013","gpsPrecision":"10","id":332,"version":1},{"lat":"37.90264737792313","lon":"-4.789875196292996","hora":"Sun Jan 27 10:42:59 UTC 2013","gpsPrecision":"15","id":304,"version":1},{"lat":"37.889775331132114","lon":"-4.781513074412942","hora":"Tue Jan 29 07:08:14 UTC 2013","gpsPrecision":"30","id":379,"version":1},{"lat":"37.89203643333167","lon":"-4.781115939840674","hora":"Tue Jan 29 07:03:26 UTC 2013","gpsPrecision":"15","id":377,"version":1},{"lat":"37.89547213353217","lon":"-4.779314082115889","hora":"Mon Jan 28 06:58:00 UTC 2013","gpsPrecision":"15","id":353,"version":1},{"lat":"37.89031089283526","lon":"-4.7963731829077005","hora":"Sun Jan 27 11:41:30 UTC 2013","gpsPrecision":"15","id":311,"version":1},{"lat":"37.889814767986536","lon":"-4.798061046749353","hora":"Sun Jan 27 11:31:12 UTC 2013","gpsPrecision":"15","id":307,"version":1},{"lat":"37.89026508573443","lon":"-4.796568481251597","hora":"Sun Jan 27 11:39:28 UTC 2013","gpsPrecision":"10","id":310,"version":1},{"lat":"37.896473980508745","lon":"-4.779459089040756","hora":"Mon Jan 28 14:20:49 UTC 2013","gpsPrecision":"15","id":369,"version":1},{"lat":"37.88855438120663","lon":"-4.791907137259841","hora":"Sun Jan 27 13:22:59 UTC 2013","gpsPrecision":"15","id":345,"version":1},{"lat":"37.89414800237864","lon":"-4.779313495382667","hora":"Tue Jan 29 06:59:23 UTC 2013","gpsPrecision":"15","id":373,"version":1},{"lat":"37.89408438373357","lon":"-4.780435413122177","hora":"Mon Jan 28 14:17:03 UTC 2013","gpsPrecision":"15","id":366,"version":1},{"lat":"37.89638253394514","lon":"-4.778162324801087","hora":"Sat Jan 26 18:37:00 UTC 2013","gpsPrecision":"50","id":292,"version":1},{"lat":"37.89075467269868","lon":"-4.795929444953799","hora":"Sun Jan 27 11:44:08 UTC 2013","gpsPrecision":"15","id":315,"version":1},{"lat":"37.88985148072243","lon":"-4.798140004277229","hora":"Sun Jan 27 11:28:23 UTC 2013","gpsPrecision":"15","id":306,"version":1},{"lat":"37.89283388759941","lon":"-4.7811356373131275","hora":"Mon Jan 28 14:12:44 UTC 2013","gpsPrecision":"15","id":362,"version":1},{"lat":"37.88926634006202","lon":"-4.792585400864482","hora":"Sun Jan 27 12:12:19 UTC 2013","gpsPrecision":"15","id":334,"version":1},{"lat":"37.89370208512992","lon":"-4.779663607478142","hora":"Sun Jan 27 09:30:03 UTC 2013","gpsPrecision":"50","id":303,"version":1},{"lat":"37.8913993248716","lon":"-4.7813603561371565","hora":"Tue Jan 29 07:04:31 UTC 2013","gpsPrecision":"5","id":378,"version":1},{"lat":"37.89283388759941","lon":"-4.7811356373131275","hora":"Mon Jan 28 14:12:47 UTC 2013","gpsPrecision":"15","id":363,"version":1},{"lat":"37.88860136177391","lon":"-4.792478699237108","hora":"Sun Jan 27 12:22:47 UTC 2013","gpsPrecision":"10","id":337,"version":1},{"lat":"37.890234240330756","lon":"-4.796578204259276","hora":"Sun Jan 27 11:39:08 UTC 2013","gpsPrecision":"15","id":309,"version":1},{"lat":"37.89024631027132","lon":"-4.797059157863259","hora":"Sun Jan 27 11:58:25 UTC 2013","gpsPrecision":"15","id":329,"version":1},{"lat":"37.891088062897325","lon":"-4.796155001968145","hora":"Sun Jan 27 11:54:44 UTC 2013","gpsPrecision":"10","id":326,"version":1},{"lat":"37.892901697196066","lon":"-4.780792482197285","hora":"Mon Jan 28 14:13:55 UTC 2013","gpsPrecision":"15","id":364,"version":1},{"lat":"37.89242321625352","lon":"-4.781285589560866","hora":"Tue Jan 29 14:13:00 UTC 2013","gpsPrecision":"5","id":383,"version":1}],"id":291,"version":92},{"nick":"ff","comment":"","activity":"Walk","color":"FFFF00","abbr":"f","lat":null,"lon":null,"online":null,"latency":"60000","deviceId":"172.30.49.33","mode":"","refresh":"30000","gpsPrecision":null,"positions":[],"id":301,"version":2},{"nick":"","comment":"","activity":"Walk","color":"FFFF00","abbr":"","lat":null,"lon":null,"online":null,"latency":"60000","deviceId":"172.30.49.21","mode":"","refresh":"30000","gpsPrecision":null,"positions":[],"id":357,"version":1},{"nick":"","comment":"","activity":"Walk","color":"FFFF00","abbr":"","lat":null,"lon":null,"online":null,"latency":"60000","deviceId":"172.30.49.31","mode":"","refresh":"30000","gpsPrecision":null,"positions":[],"id":358,"version":1},{"nick":"","comment":"","activity":"Walk","color":"FFFF00","abbr":"","lat":null,"lon":null,"online":null,"latency":"60000","deviceId":"172.30.49.29","mode":"","refresh":"30000","gpsPrecision":null,"positions":[],"id":371,"version":1},{"nick":"","comment":"","activity":"Walk","color":"FFFF00","abbr":"","lat":null,"lon":null,"online":null,"latency":"60000","deviceId":"172.30.49.24","mode":"","refresh":"30000","gpsPrecision":null,"positions":[],"id":380,"version":1}];

            // Convert Object to JSON
            var jsonObject = JSON.stringify(items);

            // Display JSON
            $('#json').text(jsonObject);

            // Convert JSON to CSV & Display CSV
            $('#csv').text(ConvertToCSV(jsonObject));
        });
    </script>
</head>
<body>
    <h1>
        JSON</h1>
    <pre id="json"></pre>
    <h1>
        CSV</h1>
    <pre id="csv"></pre>
</body>
</html>
